﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace SBWLogReader
{
    class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
            

            // Old console application code
            // ----------------------------
        //    int totalOutPackets = 0;
        //    int totalInPackets = 0;
        //    int outPacketsIndex = 2;
        //    int inPacketsIndex = 3;
        //    float kbInMb = 1024;

        //    // Get the directory containing the log files from the user
        //    Console.Write("Log file directory: ");
        //    string logFileDirectory = Console.ReadLine();
        //    Console.WriteLine();

        //    DirectoryInfo dirInfo = new DirectoryInfo(logFileDirectory);
            
        //    // Loop through each log file
        //    foreach (FileInfo file in dirInfo.GetFiles())
        //    {
        //        int outPackets = 0;
        //        int inPackets = 0;
        //        float outMB = 0;
        //        float inMB = 0;
                
        //        StreamReader reader = new StreamReader(file.FullName);

        //        while (reader.Peek() != -1)
        //        {
        //            string[] line = reader.ReadLine().Split(',');

        //            // Get the out and in packet counts
        //            if (line.Length > 3)
        //            {
        //                outPackets += int.Parse(line[outPacketsIndex]);
        //                inPackets += int.Parse(line[inPacketsIndex]);                        
        //            }
        //        }

        //        reader.Close();

        //        totalOutPackets += outPackets;
        //        totalInPackets += inPackets;

        //        outMB = (outPackets * 4) / kbInMb;
        //        inMB = (inPackets * 4) / kbInMb;

        //        // Display the results for this instance
        //        Console.WriteLine(file.Name);
        //        for (int i = 0; i < file.Name.Length; i++)
        //            Console.Write("-");
        //        Console.WriteLine();
        //        Console.WriteLine(string.Format("{0:0,0}", outPackets) + " Packets Out");
        //        Console.WriteLine(string.Format("{0:0,0}", inPackets) + " Packets In");
        //        Console.WriteLine(string.Format("{0:0,0}", outPackets + inPackets) + " Total Packets");
        //        Console.WriteLine();

        //        Console.WriteLine(string.Format("{0:0,0.##}", outMB) + " MB Out");
        //        Console.WriteLine(string.Format("{0:0,0.##}", inMB) + " MB In");
        //        Console.WriteLine(string.Format("{0:0,0.##}", outMB + inMB) + " Total MB");
        //        Console.WriteLine();
        //        Console.WriteLine();
        //        Console.WriteLine();                
        //    }

        //    float totalOutMB = (totalOutPackets * 4) / kbInMb;
        //    float totalInMB = (totalInPackets * 4) / kbInMb;
                

        //    // Display the results for all instances
        //    Console.WriteLine("Totals");
        //    Console.WriteLine("------");
        //    Console.WriteLine(string.Format("{0:0,0}", totalOutPackets) + " Packets Out");
        //    Console.WriteLine(string.Format("{0:0,0}", totalInPackets) + " Packets In");
        //    Console.WriteLine(string.Format("{0:0,0}", totalOutPackets + totalInPackets) + " Total Packets");
        //    Console.WriteLine();

        //    Console.WriteLine(string.Format("{0:0,0.##}", totalOutMB) + " MB Out");
        //    Console.WriteLine(string.Format("{0:0,0.##}", totalInMB) + " MB In");
        //    Console.WriteLine(string.Format("{0:0,0.##}", totalOutMB + totalInMB) + " Total MB");
        //    Console.WriteLine();
        //    Console.WriteLine();
        //    Console.WriteLine();

        //    Console.WriteLine("Press any key to close...");
        //    Console.ReadLine();
        }
    }
}

// Log file directory: C:\SQLBWLogs

// SBVR.log
// --------
// 59,641 Packets Out
// 68,895 Packets In
// 128,536 Total Packets 

// 232.97 MB Out
// 269.12 MB In
// 502.09 Total MB


// SCM.log
// -------
// 86,256 Packets Out
// 95,607 Packets In
// 181,863 Total Packets

// 336.94 MB Out
// 373.46 MB In
// 710.4 Total MB


// SFGP.log
// --------
// 59,541 Packets Out
// 65,206 Packets In
// 124,747 Total Packets

// 232.58 MB Out
// 254.71 MB In
// 487.29 Total MB


// Totals
// ------
// 205,438 Packets Out
// 229,708 Packets In
// 435,146 Total Packets

// 802.49 MB Out
// 897.3 MB In
// 1,699.79 Total MB
 
// Press any key to close...